/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package memory;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author DAM110
 */
public class ConectarCliente extends Thread{
    
    
    private Socket cliente;
    private Puntuacion p;
    private ObjectInputStream in;
    private ObjectOutputStream out;
    private int intentos = 0;

    public ConectarCliente(Puntuacion p) {
        
        this.p = p;        
    }
    
    @Override
    public void run(){
        
        iniciarConexion();
    }
    
    public void iniciarConexion(){
       
       if(intentos < 3){      
       
       try {
            
           this.cliente = new Socket("127.0.0.1",6000);
           if(cliente.isConnected()){
               System.out.println("Conectado");
           }
           
           
                out = new ObjectOutputStream(cliente.getOutputStream());
                
                ArrayList<Jugador> enviar = new ArrayList();
                enviar.addAll(p);
                out.writeObject(enviar);         
                
           
            } catch (UnknownHostException ex) {
            
                intentos++;
                iniciarConexion();                
            } catch (IOException ex) {
            
                intentos++;
                iniciarConexion();
            }
       
       
       }
       else{
           
       }
    }

    
    }

